package com.dongdongshop.controller;

import com.dk.data.R;
import com.dongdongshop.excetion.LoginException;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.TsellerService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import static com.dk.enums.ResultEnum.*;

//商家管理
@Controller
@RequestMapping("seller")
public class TbsellerController {



    @DubboReference
    TsellerService ts;



    //注册增加
    @RequestMapping("addsell")
    @ResponseBody
    public R addsell(TbSeller tsr){
        ts.addsell(tsr);
        return R.ok();
    }


    //登录
    @RequestMapping("denglu")
    @ResponseBody
    public R shirodeng(String sellerId, String password){

        Subject subject= SecurityUtils.getSubject();//获取到subject
        UsernamePasswordToken token=new UsernamePasswordToken(sellerId,password);//封装token到LoginRealm类

        try {
            subject.login(token);
        }catch (UnknownAccountException e){
            return R.response(USER_NULL);//用户名不存在
        }catch (IncorrectCredentialsException e){
            return R.response(PASS_ERROR);//密码错误
        }catch (LoginException e){
            return R.response(USER_ERROR);//账号未审核异常
        }
        return R.ok();//登录成功
    }










}
